// VariableScoperTest.cpp : Defines the entry point for the console application.
//
#include "AdderVariableScoper.h"
#include "AdderString.h"

void debug(AdderVariableScoper * v);

int main(int argc, char* argv[])
{
	// AdderString tests here.
	AdderString a("test");
	printf("%s\n", a.c_str());
	a << "another string";
	printf("%s\n", a.c_str());
	a << ".\nNow concatenating a floating point integer: " << 5.0f;
	printf("%s\n", a.c_str());

	AdderString b("abc");
	if (b == "abc")
		printf("[PASS] b is 'abc'.\n");
	else
		printf("[FAIL] b is not 'abc'.\n");
	AdderString c("abc");
	if (b == c)
		printf("[PASS] b is c.\n");
	else
		printf("[FAIL] b is not c.\n");
	AdderString d("abcd");
	if (b == d)
		printf("[FAIL] b is d.\n");
	else
		printf("[PASS] b is not d.\n");

	// Variable Scoper tests below here.
	printf("--------------------------------------\n");
	printf("Initial test (0,3 are set): \n");
	AdderVariableScoper v(5);
	v[0]->type = AdderValueType::NUMBER;
	v[0]->r_number = 5.0f;
	v[3]->type = AdderValueType::STRING;
	v[3]->a_string() = "Testing 123!";

	debug(&v);

	printf("Erasing (2,3 are erased): \n\n");
	v.erase(2);
	v.erase(3);

	debug(&v);

	printf("Raising (0,1,4 are set): \n\n");
	v.raise();

	v[1]->type = AdderValueType::NUMBER;
	v[1]->r_number = 70.0f;
	v[4]->type = AdderValueType::STRING;
	v[4]->a_string() = "Blarghh!";
	v[0]->type = AdderValueType::OBJECT;

	debug(&v);

	printf("Lowering: \n\n");
	v.lower();

	debug(&v);

	printf("Raising (2 set): \n\n");
	v.raise();

	v[2]->type = AdderValueType::ARRAY;

	debug(&v);

	return 0;
}

void debug(AdderVariableScoper * v)
{
	for (unsigned int i = 0; i < v->size(); i++)
	{
		if (v->exists(i))
		{
			AdderValue * t = (*v)[i];
			if (t->type == AdderValueType::STRING)
				printf("%i exists (string, \"%s\").\n", i, t->a_string().c_str());
			else if (t->type == AdderValueType::NUMBER)
				printf("%i exists (number, %f).\n", i, t->r_number);
			else
				printf("%i exists (array / object).\n", i);
		}
		else
		{
			printf("%i does not exist.\n", i);
		}
	}
	printf("--------------------------------------\n");
}

